package com.shisan.tingshu.album.rpc;

import com.shisan.tingshu.album.service.AlbumInfoService;
import com.shisan.tingshu.album.service.BaseCategoryService;
import com.shisan.tingshu.album.service.TrackInfoService;
import com.shisan.tingshu.common.result.Result;
import com.shisan.tingshu.model.album.AlbumInfo;
import com.shisan.tingshu.model.album.BaseCategory3;
import com.shisan.tingshu.model.album.BaseCategoryView;
import com.shisan.tingshu.model.album.TrackInfo;
import com.shisan.tingshu.vo.album.AlbumStatVo;
import com.shisan.tingshu.vo.album.TrackListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController // 标记该类为 REST 控制器，它会自动将方法的返回值转换为 JSON 格式
@RequestMapping("/rpc/inner/albuminfo") // 指定该控制器处理的请求路径前缀为 `/rpc/inner/albuminfo`
public class AlbumInfoRpcController  { // 是一个 REST 控制器，用于处理 HTTP 请求并调用相应的服务方法

    @Autowired
    private AlbumInfoService albumInfoService;

    @Autowired
    private BaseCategoryService baseCategoryService;

    @Autowired
    private TrackInfoService trackInfoService;

    /**
     * 获取专辑详情
     * @param albumId
     * @return
     */
    // 将 HTTP GET 请求映射到 `/getAlbumInfoAndAttrvalue/{albumId}` 路径
    @GetMapping("/getAlbumInfoAndAttrValue/{albumId}")
    // 处理请求的方法，它调用 `albumInfoService.getAlbumInfo(albumId)` 方法获取专辑信息，并将结果封装到 `Result` 对象中返回
    Result<AlbumInfo> getAlbumInfoAndAttrValue(@PathVariable(value = "albumId") Long albumId) {

        AlbumInfo albumInfo = albumInfoService.getAlbumInfo(albumId);

        return Result.ok(albumInfo);
    }

    /**
     * 获取专辑分类
     * @param albumId
     * @return
     */
    @GetMapping("/getAlbumCategory/{albumId}")
    Result<BaseCategoryView> getAlbumCategory(@PathVariable(value = "albumId") Long albumId) {

        BaseCategoryView baseCategoryView = baseCategoryService.getAlbumCategory(albumId);

        return Result.ok(baseCategoryView);
    }

    /**
     * 获取专辑统计信息
     * @param albumId
     * @return
     */
    @GetMapping("/getAlbumStat/{albumId}")
    Result<AlbumStatVo> getAlbumStat(@PathVariable(value = "albumId") Long albumId) {

        AlbumStatVo albumStatVo = albumInfoService.getAlbumStat(albumId);

        return Result.ok(albumStatVo);
    }

    /**
     * 根据一级分类id查询该一级分类下的置顶的三级分类集合
     * @param c1Id
     * @return
     */
    @GetMapping("/getBaseCategory3ListByC1Id/{albumId}")
    Result<List<BaseCategory3>> getBaseCategory3ListByC1Id(@PathVariable(value = "albumId") Long c1Id) {
        List<BaseCategory3> topBaseCategory3 = baseCategoryService.findTopBaseCategory3(c1Id);
        return Result.ok(topBaseCategory3);
    }

    /**
     * 查询全平台的一级分类id
     * @return
     */
    @GetMapping("/getAllCategory1Id")
    Result<List<Long>> getAllCategory1Id() {
        List<Long> c1Ids = baseCategoryService.getAllCategory1Id();
        return Result.ok(c1Ids);
    }

    /**
     * 根据声音id集合，查询声音对象集合
     * @param trackIdList
     * @return
     */
    @PostMapping("/getTrackListByIds")
    Result<List<TrackListVo>> getTrackListByIds(@RequestBody List<Long> trackIdList) {

        List<TrackListVo> trackListVoList = trackInfoService.getTrackListByIds(trackIdList);
        return Result.ok(trackListVoList);
    }

    /**
     * 查询所有的专辑id集合
     * @return
     */
    @GetMapping("/getAlbumInfoIdList")
    Result<List<Long>> getAlbumInfoIdList() {

        List<Long> albumIdList = albumInfoService.getAlbumInfoIdList();
        return Result.ok(albumIdList);
    }

    /**
     * 查询指定集数的声音列表
     * @param userId
     * @param trackId
     * @param trackCount
     * @return
     */
    @GetMapping("/getTrackListByCurrentTrackId/{userId}/{trackId}/{trackCount}")
    Result<List<TrackInfo>> getTrackListByCurrentTrackId(@PathVariable(value = "userId") Long userId,
                                                         @PathVariable(value = "trackId") Long trackId,
                                                         @PathVariable(value = "trackCount") Integer trackCount) {

        List<TrackInfo> trackInfoList = trackInfoService.getTrackListByCurrentTrackId(userId, trackId, trackCount);
        return Result.ok(trackInfoList);
    }

    /**
     * 查询声音对象
     * @param trackId
     * @return
     */
    @GetMapping("/getTrackInfoByTrackId/{trackId}")
    Result<TrackInfo> getTrackInfoByTrackId(@PathVariable(value = "trackId") Long trackId) {

        TrackInfo trackInfo = trackInfoService.getById(trackId);
        return Result.ok(trackInfo);
    }

    /**
     * 查询专辑对象
     * @param trackId
     * @return
     */
    @GetMapping("/getAlbumInfoByTrackId/{trackId}")
    Result<AlbumInfo> getAlbumInfoByTrackId(@PathVariable(value = "trackId") Long trackId) {

        AlbumInfo albumInfo = albumInfoService.getAlbumInfoByTrackId(trackId);
        return Result.ok(albumInfo);
    }
}